﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Collections.Generic;
using WeChat.Common2;
using System.Web.Script.Serialization;
//ashx程序为快速更新接口，类文件为管理系统调用接口
namespace WeChat.Common
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class SetMenu1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            //menuJson为菜单json
            string menuJson = SetMenu.setMenuJson();
            
            //获取access_token
            string accesstoken = GetAccess_token.getAccesstoken();
            string url = " https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" + accesstoken;
            GetReturnJson gt = new GetReturnJson();

            //Dictionary<string, object> da = gt.postReturnJson(url, menuJson);
            var js = new JavaScriptSerializer();
            var da = js.Deserialize<Dictionary<string, object>>(gt.postReturnJson(url, menuJson));

            if (da["errcode"].ToString().Equals("0"))
            {
                ApplicationLog.Write("菜单请求成功！");
                ApplicationLog.Write("菜单json:" + menuJson);
            }
            else
            {
                ApplicationLog.Write("菜单请求失败！errcode：" + da["errcode"]);
                ApplicationLog.Write("菜单json:" + menuJson);
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}